import { defineStore } from "pinia";
import axios from "axios";
import { nanoid } from "nanoid";
import { reactive } from "vue";

// export const useLoveTalkStore = defineStore('lovetalk', {
//     state() {
//         return {
//             // talkList: [
//             //     { id: 'abdfag01', title: '今天你有一点怪，哪里怪？怪好看的！' },
//             //     { id: 'abdfag02', title: '草莓、蓝莓、蔓越莓，今天想我了没？' },
//             //     { id: 'abdfag03', title: '心里给你留了一块地，我的死心塌地~' },
//             // ]
//             talkList: JSON.parse(localStorage.getItem('loveTalkStore') as string) || []
//         }
//     },
//     actions: {
//         async getATalk() {
//             let { data: { content: title } } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
//             let obj = { id: nanoid(), title };
//             this.talkList.push(obj);
//         }
//     }
// });

// 组合式写法
export const useLoveTalkStore = defineStore('lovetalk', () => {
    const talkList = reactive([
        { id: 'abdfag01', title: '今天你有一点怪，哪里怪？怪好看的！' },
        { id: 'abdfag02', title: '草莓、蓝莓、蔓越莓，今天想我了没？' },
        { id: 'abdfag03', title: '心里给你留了一块地，我的死心塌地~' },
    ]);

    async function getATalk() {
        let { data: { content: title } } = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json');
        let obj = { id: nanoid(), title };
        talkList.push(obj);
    };

    return { talkList, getATalk }
});